const axios = require('axios').default;
const cheerio = require('cheerio');
const boke = require("../models/boke");

async function getBokesDetail(BokeUrl){
    const resp = await axios.get(BokeUrl)
    const $ = cheerio.load(resp.data)
    var arr=[]
    for(i=0;i<$('.blog-list-box-top').children().length;i++){
        let obj={}
        obj.Boketit=$(`.blog-list-box-top:eq(${i})`).children().text().trim()
        obj.Bokecontent=$(`.blog-list-content:eq(${i})`).text().trim()
        // obj.Boketextcontent=$("#content_views").html();
        obj.ReleaseTime=$(`.view-time-box:eq(${i})`).text().trim()
        obj.Reading=$(`.view-num:eq(${i})`).text().trim().slice(0,3)
        arr.push(obj)
    }
    return arr
} 

// getBokesDetail('https://blog.csdn.net/qq_46075739?spm=1000.2115.3001.5343')

async function saveToDB() {
    var bokes= await getBokesDetail('https://blog.csdn.net/qq_46075739?spm=1000.2115.3001.5343')
    console.log(bokes)
    await  boke.bulkCreate(bokes)
}
saveToDB()